home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Talks & Papers / Timothy Knox / yerk 3.66 / Supplement / my stuff / copyBits next >
Text File  |  1994-06-24  |  3KB  |  92 lines

  1. \ offscreen bitmap support
  2.  
  3. :CLASS bitMap  <Super barray
  4.  
  5.     Var        BaseAddr
  6.     Int        RowBytes
  7.     Rect    BndsRect
  8.  
  9.     \ (  n  l t r b -- )
  10.     :M  PUT:   Put:  bndsRect  Put: RowBytes
  11.         idxbase +base Put: BaseAddr  ;M
  12.  
  13. ;CLASS
  14.  
  15. :CLASS copier <super grafPort
  16.  
  17.     var        destPort    \ destination grafPort (abs)
  18.     rect    destRect    \ destination rectangle
  19.     var        offscreen    \ hold copy of bitmap address
  20.     int        mode        \ copy mode
  21.     var        myWindow    \ hold yerk memory location of destport...new: does +base 
  22.                         \  and places in destport
  23.  
  24. \ **** initialize ****
  25.  
  26.   :M mode: ( n --) put: mode ;M
  27.  
  28.   :M destPort: ( window --) put: myWindow ;M
  29.  
  30.   :M destRect: ( l t r b --)  put: destRect ;M
  31.  
  32. \ **** creation ****
  33.  
  34.   :M open: (abs) call openPort ;M
  35.  
  36.   :M rowBytes: ( -- n) size: destRect drop 15 + 4 >> 1 << ;M
  37.  
  38.   :M new: { \ myBitMap rows -- }
  39.     get: myWindow +base put: destPort
  40.     pushPort                            \ save the current port
  41.     open: self
  42.     rowBytes: self -> rows                \ calc rowbytes
  43.     rows size: destRect swap drop *        \ calc size of bitmap
  44.     heap> bitMap -> myBitMap            \ create bitmap on heap
  45.     rows get: destRect put: myBitMap    \ init bitmap
  46.     myBitMap put: offScreen                \ store pointer for disposing
  47.     set: self                    \ set bitmap to grafport
  48.     myBitMap +base call setPortBits
  49.     get: destRect ^base 16 + put: rect
  50.     popPort ;M
  51.  
  52.   :M close: (abs) call closePort dispose: offscreen ;M
  53.  
  54. \ *** manipulation ****
  55.  
  56.   :M draw: ^base 2+ +base obj: destPort 2+
  57.     (abs) 16 +  abs: destRect
  58.     int: mode
  59.     get: destPort -base 24 + @ call copyBits ;M    \ draw in visrgn of destPort
  60.  
  61.   :M save: obj: destPort 2+ ^base 2+ +base
  62.     abs: destRect (abs) 16 +
  63.     word0 get: destPort -base 24 + @ call copyBits ;M    \ write over previous
  64.  
  65.   :M offset: ( dx dy -- ) offset: destRect ;M
  66.  
  67.   :M moveTo: { x y -- } x getTopX: destRect - y getTopY: destRect -
  68.     offset: destRect ;M
  69.  
  70.   :M clear: clear: [ obj: offScreen ] ;M
  71.  
  72. ;CLASS
  73.  
  74. \ example
  75. \ copier bob
  76. \ 30 30 130 130 destrect: bob \ getrect: myPort destrect: bob
  77. \ fwind destport: bob
  78. \ new: bob
  79. \ set: fwind
  80. \ to draw into offscreen bitmap: 'set: bob' then all output to
  81. \   screen goes offscreen. To draw bitmap to desport, 'draw: bob'
  82. \ to save what is in destrect in destport, 'save: bob'.
  83.  
  84. \ sequence should be
  85. \ destrect, destport, mode?
  86. \ new:  which creates bitmap, stores into grafport, and putrect
  87.  
  88. \ Any rectangular area within a window could be the destrect, even the
  89. \  port.rect. save: copies the window into the offscreen bitmap
  90. \  and draw: will return it to the window.
  91. \ Alternatively, one could set: the copier object, draw into it,
  92. \  then draw:...this will draw into the visrgn of the dest window.